using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;

namespace SeleniumTests
{
[TestFixture]
public class login
{
private ISelenium selenium;
private StringBuilder verificationErrors;
//private StringBuilder error;

[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://login.vancl.com/Login/Login.aspx");
selenium.Start();
verificationErrors = new StringBuilder();
//error = new StringBuiler();
}

[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
//Assert.AreEqual("", verificationErrors.ToString());
}
catch (Exception)
{
	//verificationErrors.Append(verificationErrors.ToString());
// Ignore errors if unable to close the browser
}
//error.ToString();
Assert.AreEqual("", verificationErrors.ToString());
}

[Test]
public void TheLoginTest()
{
			//selenium.Open("http://my.vancl.com");
			selenium.Open("/Login/Login.aspx");
			//selenium.refresh();
			string name = @{param};
			string password = @{param};
			selenium.Type("id=vanclUserName", name);
			selenium.Type("id=vanclPassword", password);
			selenium.Click("id=vanclLogin");
			Thread.Sleep(5000);			
			
			bool isPageRedirect = @{param};
			//Assert.AreNotEqual("https://login.vancl.com/Login/Login.aspx", selenium.GetLocation()) == isPageRedirect;
			Assert.IsTrue(("https://login.vancl.com/Login/Login.aspx"==selenium.GetLocation()) == isPageRedirect,"page redirect error");
			if(!isPageRedirect) continue;
			
			bool usernameError = @{param};
			Assert.IsTrue(selenium.IsVisible("id=vanclUserNameError") == usernameError,"username error:"+name);
			if (usernameError) continue;
			
			bool passwordError = @{param};
			Assert.IsTrue(selenium.IsVisible("id=vanclPasswordError") == passwordError, "password error:"+password);
			if (passwordError) continue;
			
			bool isLoginError = @{param};
			Assert.IsTrue(selenium.IsVisible("id=vanclLoginError") == isLoginError,"login error:"+name+","+password);
			if(isLoginError) continue;					

			
			//try
			//{
				//Assert.AreNotEqual("https://login.vancl.com/Login/Login.aspx", selenium.GetLocation());
			//}
			//catch(AssertionException e)
			//{
				//verificationErrors.Append("page not redirect:"+e.Message);
			//}
			//try
			//{
				//Assert.IsFalse(selenium.IsElementPresent("id=vanclUserNameError"));
			//}
			//catch (AssertionException e)
			//{
				//verificationErrors.Append("username error:"+e.Message);
			//}
			//try
			//{
				//Assert.IsFalse(selenium.IsElementPresent("id=vanclPasswordError"));
			//}
			//catch (AssertionException e)
			//{
				//verificationErrors.Append("password error:"+e.Message);
			//}
			//try
			//{
				//Assert.IsFalse(selenium.IsElementPresent("id=vanclLoginError"));
			//}
			//catch (AssertionException e)
			//{
				//verificationErrors.Append("page login error:"+e.Message);
			//}
}
}
}
